{{template "admin/header.html"}}
<title>save - GPRESS</title>
{{template "admin/bodystart.html"}}
{{ $tableFiled := tableFiled .urlPathParam }}
{{$fieldType := fieldType}}
{{ $category := category }} <!-- 导航数据 -->
{{ $pageTemplate := pageTemplate }} <!-- 模版数据 -->

<section class="section">
	<input type="hidden" id="basePath" value="{{basePath}}">

	<div class="container">
		<div class="table-content">
			<!-- is-6-desktop is-6-tablet -->
			<div class="column">
				<form id="gpress-form" action="{{basePath}}admin/{{.urlPathParam}}/save" method="POST">
					<ul class="save-ul">
						<li>
							<div class="left">
								ID
							</div>
							<div class="right">
								<input class="input" type="text" name="id" id="id">
							</div>
						</li>
						<li>
							<div class="left">
								菜单名称
							</div>
							<div class="right">
								<input class="input" type="text" name="name" id="name">
							</div>
						</li>
						<li>
							<div class="left">
								跳转路径
							</div>
							<div class="right">
								<input class="input" type="text" name="hrefURL" id="hrefURL">
							</div>
						</li>
						<li>
							<div class="left">
								跳转方式
							</div>
							<div class="right">
								<input class="input" type="text" name="hrefTarget" id="hrefTarget">
							</div>
						</li>
						<li>
							<div class="left">
								父菜单ID
							</div>
							<div class="right">
								<input class="input" type="text" name="pid" id="pid">
							</div>
						</li>
						<li>
							<div class="left">
								PC主题
							</div>
							<div class="right">
								<input class="input" type="text" name="themePC" id="themePC">
							</div>
						</li>
						<li>
							<div class="left">
								模型ID
							</div>
							<div class="right">
								<input class="input" type="text" name="moduleID" id="moduleID">
							</div>
						</li>
						<li>
							<div class="left">
								页面模版
							</div>
							<div class="right">
								<select class="input" id="templateSelect">
									<option value="">请选择</option>
									{{ range $index,$obj := $pageTemplate }}
									<option value='{{$obj.id}}'>{{$obj.name}}</option>
									{{end}}
								</select>
							</div>
						</li>
						<li>
							<div class="left">
								子页面模版ID
							</div>
							<div class="right">
								<input class="input" type="text" name="childTemplateID" id="childTemplateID">
							</div>
						</li>
						<li>
							<div class="left">
								创建人
							</div>
							<div class="right">
								<input class="input" type="text" name="createUser" id="createUser">
							</div>
						</li>
						<li>
							<div class="left">
								排序
							</div>
							<div class="right">
								<input class="input" type="number" name="sortNo" id="sortNo">
							</div>
						</li>
						<li>
							<div class="left">
								是否有效
							</div>
							<div class="right">
								<input class="input" type="number" value="1" name="status" id="status">
							</div>
						</li>
					</ul>
					<div class="field is-grouped" style="padding-left: 190px;">
						<div class="control">
							<button type="submit" class="button is-primary">提交</button>
						</div>
						<div class="control">
							<button type="reset" class="button is-info is-light">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</section>
<link href="https://cdn.staticfile.org/wangeditor5/5.1.23/css/style.min.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/wangeditor5/5.1.23/index.min.js"></script>
<script type="text/javascript" src="{{basePath}}admin/js/cherry-markdown.min.js"></script>
<script>
	let templateID = ''
	$('#templateSelect').change(function(e) {
		templateID = $('#templateSelect').val()
	})
	// 保存提交
	const form = document.querySelector('#gpress-form')
	form.addEventListener('submit', async event => {
		event.preventDefault()
		const formData = new FormData(form)
		const jsonObject = {}
		for (const [key, value] of formData.entries()) {
			const fieldType = document.querySelector(key)
			if (!!fieldType && fieldType == 1) {
				jsonObject[key] = parseInt(value)
			}
			else {
				jsonObject[key] = value
			}
		}
		jsonObject.templateID = templateID
		const response = await fetch(form.action, {
			method: form.method,
			body: JSON.stringify(jsonObject),
			headers: { 'Content-Type': 'application/json' }
		})
		let res = await response.json()
		if (res.statusCode == 200) {
			$.confirm({
				useBootstrap: false,
				boxWidth: '400px',
				title: '提示',
				content: '保存成功！',
				type: 'green',
				buttons: {
					'确定': function() {
						window.location.href = '{{basePath}}admin/{{.urlPathParam}}/list'
					}
				}
			})
		}
	})
</script>


{{template "admin/bodyend.html"}}
